15 openstreetmap
Uncomment the following line to install leafmap if needed.
In [1]:
# !pip install geopandas osmnx leafmap
In [2]:
import leafmap
Adds OSM data of place(s) by name or ID to the map.
In [3]:
m = leafmap.Map(google_map=None, toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
m = leafmap.Map(google_map=None, toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Adds OSM entities within boundaries of geocodable place(s) to the map.
In [5]:
m = leafmap.Map(google_map=None, toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Shows OSM feature tags.
In [6]:
# leafmap.osm_tags_list()
Adds OSM entities within some distance N, S, E, W of address to the map.
In [7]:
m = leafmap.Map(google_map=None, toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/geopandas/_vectorized.py:142: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'Polygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) aout[:] = out /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/geopandas/_vectorized.py:142: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'MultiPolygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) aout[:] = out /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/pandas/core/dtypes/cast.py:1981: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'Polygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) result[:] = values
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
m = leafmap.Map(google_map=None, toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/geopandas/_vectorized.py:142: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'Polygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) aout[:] = out /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/geopandas/_vectorized.py:142: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'MultiPolygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) aout[:] = out /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/pandas/core/dtypes/cast.py:1981: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'Polygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) result[:] = values /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/pandas/core/dtypes/cast.py:1981: DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'MultiPolygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21) result[:] = values
2021-07-13 16:19:36 Configured OSMnx 1.1.1 2021-07-13 16:19:36 HTTP response caching is on 2021-07-13 16:19:36 Pausing 1 seconds before making HTTP GET request 2021-07-13 16:19:37 Get https://nominatim.openstreetmap.org/search?format=json&polygon_geojson=1&dedupe=0&limit=50&q=Bunker+Hill%2C+Los+Angeles%2C+California with timeout=180 2021-07-13 16:19:37 Downloaded 1.2kB from nominatim.openstreetmap.org 2021-07-13 16:19:37 Saved response to cache file "cache/8d8366ad6b96fa854a9d6d038c022b8bdcdb6fe6.json" 2021-07-13 16:19:37 Created GeoDataFrame with 1 rows from 1 queries 2021-07-13 16:19:37 Constructed place geometry polygon(s) to query API 2021-07-13 16:19:37 Projected GeoDataFrame to +proj=utm +zone=11 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2021-07-13 16:19:37 Projected GeoDataFrame to epsg:4326 2021-07-13 16:19:37 Requesting data within polygon from API in 1 request(s) 2021-07-13 16:19:37 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:19:38 Pausing 0 seconds before making HTTP POST request 2021-07-13 16:19:38 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2734.056122+-118.256052+34.050990+-118.248100+34.053625+-118.245628+34.058656+-118.253434+34.057132+-118.255014+34.056122+-118.256052%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2021-07-13 16:19:38 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:19:47 Downloaded 164.7kB from overpass-api.de 2021-07-13 16:19:47 Saved response to cache file "cache/ac8d51b3ab541d6f0ab6add8b4ae694b6f391f99.json" 2021-07-13 16:19:47 Got all geometries data within polygon from API in 1 request(s) 2021-07-13 16:19:47 Converting 1433 elements in JSON responses to geometries 2021-07-13 16:19:47 77 geometries created in the dict 2021-07-13 16:19:47 13 untagged geometries removed 2021-07-13 16:19:47 Created r-tree spatial index for 64 geometries 2021-07-13 16:19:47 Identified 64 geometries inside polygon 2021-07-13 16:19:47 0 geometries removed by the polygon filter 2021-07-13 16:19:47 8 geometries removed by the tag filter 2021-07-13 16:19:47 56 geometries in the final GeoDataFrame 2021-07-13 16:19:47 Pausing 1 seconds before making HTTP GET request 2021-07-13 16:19:48 Get https://nominatim.openstreetmap.org/search?format=json&limit=1&dedupe=0&q=New+York+City with timeout=180 2021-07-13 16:19:49 Downloaded 0.5kB from nominatim.openstreetmap.org 2021-07-13 16:19:49 Saved response to cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2021-07-13 16:19:49 Geocoded "New York City" to (40.7127281, -74.0060152) 2021-07-13 16:19:49 Created bbox 1500 m from (40.7127281, -74.0060152): 40.72621790503239,40.69923829496761,-73.98821837587228,-74.02381202412771 2021-07-13 16:19:49 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2021-07-13 16:19:49 Projected GeoDataFrame to epsg:4326 2021-07-13 16:19:49 Requesting data within polygon from API in 1 request(s) 2021-07-13 16:19:49 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:19:49 Pausing 0 seconds before making HTTP POST request 2021-07-13 16:19:49 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2021-07-13 16:19:49 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:19:52 Downloaded 35.7kB from overpass-api.de 2021-07-13 16:19:52 Saved response to cache file "cache/7d10c2e8d50f39407dda671d56290ea2808b3d4a.json" 2021-07-13 16:19:52 Got all geometries data within polygon from API in 1 request(s) 2021-07-13 16:19:52 Converting 106 elements in JSON responses to geometries 2021-07-13 16:19:52 97 geometries created in the dict 2021-07-13 16:19:52 0 untagged geometries removed 2021-07-13 16:19:52 Created r-tree spatial index for 97 geometries 2021-07-13 16:19:52 Identified 97 geometries inside polygon 2021-07-13 16:19:52 0 geometries removed by the polygon filter 2021-07-13 16:19:52 0 geometries removed by the tag filter 2021-07-13 16:19:52 97 geometries in the final GeoDataFrame 2021-07-13 16:19:53 Retrieved response from cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2021-07-13 16:19:53 Geocoded "New York City" to (40.7127281, -74.0060152) 2021-07-13 16:19:53 Created bbox 1000 m from (40.7127281, -74.0060152): 40.721721303354926,40.703734896645074,-73.99415065058152,-74.01787974941847 2021-07-13 16:19:53 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2021-07-13 16:19:53 Projected GeoDataFrame to epsg:4326 2021-07-13 16:19:53 Requesting data within polygon from API in 1 request(s) 2021-07-13 16:19:53 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:19:53 Pausing 50 seconds before making HTTP POST request 2021-07-13 16:20:43 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2021-07-13 16:20:43 Resolved overpass-api.de to 178.63.48.217 2021-07-13 16:20:52 Downloaded 2,706.2kB from overpass-api.de 2021-07-13 16:20:52 Saved response to cache file "cache/2c876f231fa35ebe028236a3fb06b51de7794ae0.json" 2021-07-13 16:20:52 Got all geometries data within polygon from API in 1 request(s) 2021-07-13 16:20:52 Converting 20844 elements in JSON responses to geometries 2021-07-13 16:20:53 2919 geometries created in the dict 2021-07-13 16:20:53 72 untagged geometries removed
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook